#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
class ThirdPartyTVLib
{
public:
    virtual void listVideos() = 0;
    virtual void getVideoInfo() = 0;
    virtual void downloadVideo(std::string videoName) = 0;
};

class ThirdPartyTV : public ThirdPartyTVLib
{
    void listVideos()
    {

    }
    virtual void getVideoInfo()
    {

    }
    virtual void downloadVideo(std::string videoName)
    {
        std::cout<<"download "<<videoName<<" from ThirdParty"<<std::endl;
    }
};

class CachedTVClass : public ThirdPartyTVLib
{
private:
    ThirdPartyTVLib *service = nullptr;
    std::unordered_map<std::string, int> map;
public:

    CachedTVClass()
    {
        service = new ThirdPartyTV();
    }
    void listVideos()
    {
        service->listVideos();
    }
    virtual void getVideoInfo()
    {

    }
    virtual void downloadVideo(std::string videoName)
    {
        if(map.find(videoName) == map.end())
        {
            service->downloadVideo(videoName);
            map[videoName] = 1;
        } else{
            std::cout<<"return from local cache"<<std::endl;
        }
    }
};

int main() {
    std::cout<<"download video using ThirdPartyTV"<<std::endl;
    ThirdPartyTVLib* tv = new ThirdPartyTV();
    tv->downloadVideo("video1");
    tv->downloadVideo("video2");
    tv->downloadVideo("video1");
    std::cout<<"download video using CachedTVClass"<<std::endl;
    ThirdPartyTVLib* cache = new CachedTVClass();
    cache->downloadVideo("video1");
    cache->downloadVideo("video2");
    cache->downloadVideo("video1");
    return 0;
}



